<template>
	<transition name="el-zoom-in-center">
		<div class="JNPF-preview-main">
			<div class="JNPF-common-page-header">
				<el-page-header @back="goBack" :content="!dataForm.id ? '新建' : isDetail ? '详情' : '编辑'"/>
				<div class="options">
					<el-button type="primary" @click="dataFormSubmit()" v-if="!isDetail">确 定</el-button>
					<el-button @click="goBack">取 消</el-button>
				</div>
			</div>
			<el-row :gutter="15"  class="main" :style="{margin: '0 auto',width:'100%'}">
			<el-form ref="elForm" :model="dataForm" size="medium" label-width="130px" label-position="right" :disabled="!!isDetail" :rules="rules">
				<el-col :span="24">
					<el-form-item label="储罐区名称" prop="cgqmc" required >
						<el-input v-model="dataForm.cgqmc" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="储罐区编号" prop="cgqbh" required >
						<el-input v-model="dataForm.cgqbh" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="在厂区的位置" prop="zcqdwz" required >
						<el-input v-model="dataForm.zcqdwz" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="所处环境功能区" prop="schjgnq" >
						<el-input v-model="dataForm.schjgnq" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="储罐区面积" prop="cgqmj" >
						<el-input v-model="dataForm.cgqmj" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="有无围堰" prop="ywwy" >
						<el-select v-model="dataForm.ywwy" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in ywwyOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="围堰所围面积" prop="wyswmj" >
						<el-input v-model="dataForm.wyswmj" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="储罐个数" prop="cggs" >
						<el-input v-model="dataForm.cggs" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="储存物质" prop="ccwz" >
						<el-input v-model="dataForm.ccwz" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="储罐区总容积" prop="cgqzrl" >
						<el-input v-model="dataForm.cgqzrl" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="常规储存量" prop="cgccl" >
						<el-input v-model="dataForm.cgccl" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="两罐间最小间距" prop="lgjzxjj" >
						<el-input v-model="dataForm.lgjzxjj" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="有无消防通道" prop="ywxftd" >
						<el-select v-model="dataForm.ywxftd" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in ywxftdOptions" :key="index" :label="item.fullName" :value="item.id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="装卸方式" prop="zxfs" >
						<el-input v-model="dataForm.zxfs" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="装卸危险化学品种类" prop="zxwxhxpzl" >
						<el-input v-model="dataForm.zxwxhxpzl" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="所属危险化学品重大危险源编码" prop="sswxhxpzdwxydy" >
						<el-select v-model="dataForm.sswxhxpzdwxydy" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in sswxhxpzdwxydyOptions" :key="index" :label="item.ZDWXYMC" :value="item.ZDWXYBM" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="现场照片" prop="xczp" >
						<JNPF-UploadImg v-model="dataForm.xczp" accept="" :fileSize="2" sizeUnit="MB" :limit="9" >
						</JNPF-UploadImg>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="经度（度）" prop="jd" >
						<el-input v-model="dataForm.jd" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="纬度（度）" prop="wd" >
						<el-input v-model="dataForm.wd" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="备注" prop="bz" >
						<el-input v-model="dataForm.bz" placeholder="请输入" clearable :style='{"width":"100%"}' prefix-icon="" suffix-icon="" >
							<template slot="prepend"></template>
							<template slot="append"></template>
						</el-input>
					</el-form-item>
				</el-col>
				<el-col :span="24">
					<el-form-item label="所属部门" prop="ssbm" >
						<el-select filterable v-model="dataForm.ssbm" placeholder="请选择" clearable :style='{"width":"100%"}' >
							<el-option v-for="(item, index) in ssbmOptions" :key="index" :label="item.F_FullName" :value="item.F_Id" ></el-option>
						</el-select>
					</el-form-item>
				</el-col>
			</el-form>
			</el-row>
		</div>
	</transition>

</template>
<script>
import request from '@/utils/request'
import {getDictionaryDataSelector}from '@/api/systemData/dictionary'
import {previewDataInterface}from '@/api/systemData/dataInterface'
export default {
    data() {
      return {
        visible: false,
        isDetail: false,
        dataForm: {
					cgqmc:undefined,
					cgqbh:undefined,//-
					zcqdwz:undefined,
					schjgnq:undefined,
					cgqmj:undefined,
					ywwy:undefined,
					wyswmj:undefined,
					cggs:undefined,
					ccwz:undefined,
					cgqzrl:undefined,
					cgccl:undefined,
					lgjzxjj:undefined,
					ywxftd:undefined,
					zxfs:undefined,
					zxwxhxpzl:undefined,
					sswxhxpzdwxydy:undefined,
					xczp:[],
					jd:undefined,
					wd:undefined,
					bz:undefined,
					ssbm:undefined,

        },
        rules: {
						cgqmc:[
						{
							required:true,
							message:'请输入储罐区名称',
							trigger:'blur'
						},
						],
						cgqbh:[
						{
							required:true,
							message:'请输入储罐区编号',
							trigger:'blur'
						},
						],
						zcqdwz:[
						{
							required:true,
							message:'请输入在厂区的位置',
							trigger:'blur'
						},
						],

        },
				ywwyOptions:[{"fullName":"无","id":"0"},{"fullName":"有","id":"1"}],
				ywxftdOptions:[{"fullName":"无","id":"0"},{"fullName":"有","id":"1"}],
				sswxhxpzdwxydyOptions:[],
				ssbmOptions:[],

      }
    },
    created() {
		this.getSswxhxpzdwxydyOptions();
		this.getSsbmOptions();

    },
    methods: {
		getSswxhxpzdwxydyOptions()
		{
			previewDataInterface('707f1102bce74818a551ebcfa88f2321').then(res => {
				this.sswxhxpzdwxydyOptions = res.data
			})
		},
		getSsbmOptions()
		{
			previewDataInterface('772d2cbcadd24df79243e3d92ef5f690').then(res => {
				this.ssbmOptions = res.data
			})
		},

           goBack() {
                    this.$emit('refresh')
                },
      init(id, isDetail) {

        this.dataForm.id = id || 0;
        this.visible = true;
        this.isDetail = isDetail || false;
        this.$nextTick(() => {
          this.$refs['elForm'].resetFields();
          if (this.dataForm.id) {
            request({
              url: '/api/System/CGQ/' + this.dataForm.id,
              method: 'get'
            }).then(res =>{
              this.dataForm = res.data;

            })
          }
        })
      },
      // 表单提交
      dataFormSubmit() {
        this.$refs['elForm'].validate((valid) => {
          if (valid) {
            if (!this.dataForm.id) {
              request({
                url: '/api/System/CGQ',
                method: 'post',
                data: this.dataForm,
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            } else {
              request({
                url: '/api/System/CGQ/' + this.dataForm.id,
                method: 'PUT',
                data: this.dataForm
              }).then((res) =>{
                this.$message({
                  message: res.msg,
                  type: 'success',
                  duration: 1000,
                  onClose: () =>{
                    this.visible = false;
                    this.$emit('refresh', true);
                  }
                })
              })
            }
          }
        })
      },

    }
  }
  </script>